<template>
  <div class="app-container">
    <el-card>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="申请编号">
          <el-input
            v-model="queryParams.applyCode"
            placeholder="请输入申请编号"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item label="老人姓名">
          <el-input
            v-model="queryParams.applyName"
            placeholder="请输入老人姓名"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="改造进度">
          <el-select
            v-model="queryParams.step"
            clearable
            placeholder="请选择改造状态"
            style="width: 240px"
          >
            <el-option
              v-for="dict in improve_progress"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search"
@click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar
          v-model:showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="postList"
        stripe
        border
        max-height="500"
      >
        <el-table-column label="申请编号" align="center" prop="applyCode" />
        <el-table-column label="老人姓名" align="center" prop="applyName" />
        <el-table-column label="性别" align="center" width="100">
          <template #default="scope">
            <span>
              {{
                sys_user_sex.find((item) => item.value == scope.row.sex)
                  ? sys_user_sex.find((item) => item.value == scope.row.sex)
                      .label
                  : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="age" width="100" />
        <el-table-column
          label="家庭住址"
          align="center"
          prop="address"
          width="600"
        />

        <el-table-column label="改造进度" align="center">
          <template #default="scope">
            <span>
              {{
                improve_progress.find((item) => item.value == scope.row.step)
                  ? improve_progress.find(
                      (item) => item.value == scope.row.step,
                    ).label
                  : ""
              }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="220"
        >
          <template #default="scope">
            <el-button link
type="primary" @click="edit(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.limit"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改岗位对话框 -->
  </div>
</template>

<script setup name="schedule">
const { proxy } = getCurrentInstance();
const { sys_normal_disable, sys_user_sex, improve_progress } = proxy.useDict(
  'sys_normal_disable',
  'sys_user_sex',
  'improve_progress',
);
import { getRemodelStep } from '@/api/AgeAppropriate/index';
import { debounce } from "@/utils/debounce.js";
import { useRouter } from 'vue-router';
const router = useRouter()

const showSearch = ref(true);
const loading = ref(true);
const postList = ref([]);
const open = ref(false);
const title = ref("新增服务项目");

const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    page: 1,
    limit: 10,
    applyCode: undefined,
    applyName: undefined,
    step: undefined,
  },
  rules: {},
});

const { queryParams, form, rules } = toRefs(data);

/** 提交按钮 */

function cancel() {
  open.value = false;
  reset();
}
function edit(data) {
  router.push({
    name: `elderlyReformInfo`,
    params: {
      id: data.id,
      step: data.step ? data.step : '1',
    },
  })
}

/** 查询岗位列表 */
function getList() {
  loading.value = true;
  getRemodelStep(queryParams.value).then((response) => {
    postList.value = response.page.list;
    total.value = response.page.totalCount;
    loading.value = false;
  })
}
function handleQuery() {
  getList();
}
function resetQuery() {
  queryParams.value = {
    page: 1,
    limit: 10,
    applyCode: undefined,
    applyName: undefined,
    step: undefined,
  };
  getList();
}

getList();
</script>
